package com.sgb.kjwl.view.widget.pick;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.LayoutPickDetailRequireBinding;
import com.sgb.kjwl.model.entity.pick.TenderDictEntity3;
import com.sgb.kjwl.view.ui.adapter.pick.PickDetailRequireAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author:         张驰
 * @CreateDate:     006
 * @UpdateUser:     张驰
 * @UpdateDate:     2020年09月24
 * @UpdateRemark:   报名详情页中投标人要求模块布局
 * @Version:        招采 2.7.2
 */
public class PickDetailRequireView extends RelativeLayout {
    private Context mContext;
    private LayoutPickDetailRequireBinding binding;
    private PickDetailRequireAdapter adapter;
    private List<TenderDictEntity3> tenderDictEntity3List = new ArrayList<>();

    public PickDetailRequireView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public PickDetailRequireView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }

    public PickDetailRequireView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.layout_pick_detail_require, this, true);
        if (adapter == null) {
            adapter = new PickDetailRequireAdapter(mContext, tenderDictEntity3List);
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        binding.pickRecycler.setLayoutManager(layoutManager);
        binding.pickRecycler.setAdapter(adapter);
        binding.pickRecycler.setLoadingMoreEnabled(false);
        binding.pickRecycler.setPullRefreshEnabled(false);
    }

    public void showInfoView(List<TenderDictEntity3> tenderDictEntity3List) {
        if (adapter == null) return;
        if (tenderDictEntity3List == null) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }
        if (tenderDictEntity3List.size() == 0) {
            binding.pickRecycler.setVisibility(View.GONE);
//            binding.emptyView.setVisibility(View.VISIBLE);
            return;
        }
        List<TenderDictEntity3> tempList = new ArrayList<>();
        for (int i = 0; i < tenderDictEntity3List.size(); i++) {
            if(!TextUtils.isEmpty(tenderDictEntity3List.get(i).getName()) || !TextUtils.isEmpty(tenderDictEntity3List.get(i).getValue())){
                tempList.add(tenderDictEntity3List.get(i));
            }
        }
        adapter.setDatas(tempList);
    }

}
